<?php

if (isset($_SESSION["message"])){
    echo $_SESSION["message"];
}

$_SESSION["message"] = "";


function upload_photo_to_db($photo_name, $photo_folder_id){
    global $db_connection;    
    
    //create thumbnail function
    // $thumbnail_photo_name = create_thumbnail();
    $thumbnail_photo_name = "";
    $photo_folder_id = "";
    
    $query = "";
    $query .= "INSERT into `gallery_photos` (";
    $query .= "`photo_name`, `thumbnail_photo_name`, `photo_folder_id`";
    $query .= ") VALUES (";
    $query .= "{$photo_name}, {$thumbnail_photo_name}, {$photo_folder_id}";
    $query .= "); ";
}

function redirect_to(){
    // TODO: header redirection
}

if(isset($_POST)){
    
    $photos = [];
    
    if(isset($_FILES["photo1"])){
        $photo1 = mysql_real_escape_string($db_connection, $_FILES["photo1"]["name"]);
        $photos["photo1"] = $photo1;
    } 
     if(isset($_FILES["photo2"])){
        $photo1 = mysql_real_escape_string($db_connection, $_FILES["photo2"]["name"]);
        $photos["photo2"] = $photo1;
    }    
    if(!empty($photos)){        
        foreach($photo as $photos){
            upload_photo_to_db($photo_name, $photo_folder_id);        
            //upload_photo_to_ftp();   // should include create_thumbnail();
        }
    }else{
        $_SESSION["message"] .= "Photos Array is empty";
        echo "right before header()";
        header('Location: gallery_admin.php');
        exit;
    }
    
    
}
?>
